//
// Created by wenyaxi on 24-10-29.
//
#include <common.h>
class Solution {
public:
    bool hasCycle(ListNode *head) {
        if (head == nullptr || head->next == nullptr) {
            return false;
        }
        ListNode *fast = head->next, *slow = head;
        while(fast!=slow) {
            if (fast==nullptr||fast->next == nullptr || fast->next->next == nullptr) {
                return false;
            }
            fast = fast->next->next;
            slow = slow->next;
        }
        return fast!=nullptr;
    }
};

int main(int argc, char *argv[]) {
    Solution s;
    ListNode *head = new ListNode(1,new ListNode(2));
    bool has_cycle = s.hasCycle(head);
    cout << has_cycle << endl;
    return 0;
}
